package com.example.studentcompetitionplatform.service.impl;

import com.example.studentcompetitionplatform.entity.Competitions;
import com.example.studentcompetitionplatform.entity.Reviews;
import com.example.studentcompetitionplatform.mapper.ReviewsMapper;
import com.example.studentcompetitionplatform.service.IReviewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ReviewsService implements IReviewsService {
    @Resource
    private ReviewsMapper reviewsMapper;

    @Override
    public void insertR(Reviews reviews) {
       if (reviewsMapper.selectReview(reviews)!=null){
           System.out.println("已经新增过了");
       }
        reviewsMapper.insertReview(reviews);
    }

    @Override
    public void deleteR(Reviews reviews) {
        reviewsMapper.deleteReview(reviews);
    }

    @Override
    public void editR(Reviews reviews) {
        reviewsMapper.editReview(reviews);
    }

    @Override
    public Map<String, Object> page(Integer pageNum, Integer pageSize, Integer reviewId) {
        pageNum = (pageNum - 1) * pageSize;
        if (reviewId == 0) {
            reviewId = null;
        }
        List<Reviews> data = reviewsMapper.selectPage(pageNum, pageSize, reviewId);
        Integer total = reviewsMapper.findReviewsTotal(reviewId);
        Map<String, Object> res = new HashMap<>();
        res.put("data", data);
        res.put("total", total);
        return res;
    }
}
